home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / DOS32.ZIP;1 / STDIO.ASM < prev   
Encoding:
Assembly Source File  |  1993-10-04  |  11.2 KB  |  426 lines

  1. comment $
  2.  
  3.  
  4.  
  5.      FOR 32 BIT PROTECDED MODE ONLY
  6.  Writen by Adam Seychell
  7.  
  8. fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
  9. fififififififififififififififififififififi  VARIOUS PROCEDURES   fififififififififififififififififififififififififififi
  10. fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
  11. fi                                                                     fi
  12. fi      THIS FILE CONTAINS USEFUL PROCEDURES                           fi
  13. fi                                                                     fi
  14. fi      THEY SHOULDN'T NEED TO BE CHANGED TO MUSH                      fi
  15. fi                                                                     fi
  16. fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
  17.  
  18.  
  19.  
  20.  
  21.  
  22. fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
  23. fififififififififififififififififififififi  VARIOUS PROCEDURES   fififififififififififififififififififififififififififi
  24. fififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififififi
  25. ’ÕÕÕÕÕÕÕÕÕÕÕÕÕ—ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  26. ≥  proc Name  ≥          Discription
  27. ΔÕÕÕÕÕÕÕÕÕÕÕÕÕÿÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  28. ≥ ClrScr      ≥    fills video memory (B8000h-B8FFFh) with  AX
  29. ≥             ≥
  30. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  31. ≥PRINT_CHAR   ≥ prints a character AL with color AH at the cursor
  32. ≥             ≥                AH = attribute byte  ( COLOR )
  33. ≥             ≥
  34. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  35. ≥ TEXT        ≥  Prints a string at the cursor position.
  36. ≥             ≥ expects  :     EDX = offset of string in data segment
  37. ≥             ≥                AH = attribute byte  ( COLOR )
  38. ≥             ≥
  39. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  40. ≥HEX_DWORD    ≥ Prints the value of EDX, DX or DL as hexidecimal
  41. ≥HEX_WORD     ≥  at the cursor position.
  42. ≥HEX_BYTE     ≥                 expects  :   EDX = value to display
  43. ≥             ≥                        AH = attribute byte  ( COLOR )
  44. ≥             ≥
  45. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  46. ≥BINARY_DWORD ≥ Same as hex above except it prints in binary
  47. ≥BINARY_WORD  ≥
  48. ≥BINARY_BYTE  ≥
  49. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  50. ≥DEC_DWORD    ≥ Same as hex above except it prints in decimal
  51. ≥DEC_WORD     ≥
  52. ≥DEC_BYTE     ≥
  53. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  54. ≥SCROLL_SCREEN≥Scrolls the screen up a line.
  55. ≥             ≥
  56. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  57. ≥SET_TIMER    ≥Sets the timer 0 register of the 8242 PIC
  58. ≥             ≥ to the value in AX
  59. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  60. ≥RANDOM       ≥returns EAX = a random number CL bits in size
  61. ≥             ≥
  62. √ƒƒƒƒƒƒƒƒƒƒƒƒƒ≈ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  63. ≥SQRT         ≥Returns EAX with the square root of EAX.
  64. ≥             ≥
  65. ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒ¡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. $
  75.  
  76. DATA32 SEGMENT PUBLIC 'DATA' USE32
  77.  
  78. ;       Various    varibles used by the procedures
  79. random_init        dd    1010111000110111101010011011b
  80. clicker                db 0
  81. HexChar            db '0123456789ABCDEF'
  82.  
  83. ; Contains the current cursor cordinates  used by the printing procs
  84. Cursor_X    db    0,0; Contain the current cursor cordinates
  85. Cursor_Y    db    0,0; used by the printing procs ( see file PROCS.INC )
  86. DATA32 ENDS
  87.  
  88.  
  89.  
  90.  
  91.  
  92. public Click
  93. public ClrScr
  94. public Scroll_Screen
  95. public Set_timer
  96. public TEXT
  97. public binary_Dword
  98. public binary_Word
  99. public binary_Byte
  100. public Hex_Dword
  101. public Hex_Word
  102. public Hex_Byte
  103. public DEC_Dword
  104. public DEC_Word
  105. public DEC_Byte
  106. public PRINT_CHAR
  107. public SQRT
  108. public Random
  109.  
  110. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ Click speaker ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  111. Click proc near
  112.        xor clicker,010b
  113.        mov al,clicker
  114.        out 61h,al
  115.        ret
  116. click endp
  117.  
  118. ; ÕÕÕÕÕÕÕÕÕÕÕÕÕÕ CLEAR THE SCREEN ( FILL WITH ATTRIBUTES AH ) ÕÕÕÕÕÕÕÕÕÕÕÕ
  119. ClrScr    proc near
  120.     PUSH edi ecx eax  es
  121.         push fs
  122.         pop  es
  123.         mov edi,0b8000h
  124.         cld
  125.         xor al,al
  126.         mov ecx,2000
  127.         rep stosw
  128.         POP es eax ecx edi
  129.         ret
  130. ClrScr endp
  131.  
  132.  
  133. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ  SCROLL THE SCREEN UP A LINE  ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  134. Scroll_Screen proc near
  135.     PUSH esi edi ecx eax es
  136.         push fs
  137.         pop es
  138.         mov edi,0b8000h
  139.         mov esi,0B8000h+0a0h
  140.         cld
  141.         mov ecx,1000-40
  142.         rep movs dword ptr  es:[edi],es:[esi]
  143.         ; now screen is scrolled up, must clear bottom line
  144.         mov ecx,80
  145. cxtln:  mov byte ptr es:[0b8000h+(80*24*2)-2+ecx*2],0
  146.         loop cxtln
  147.         POP es eax ecx edi  esi
  148.     ret
  149. Scroll_Screen endp
  150.  
  151.  
  152. Set_timer  proc near
  153. ;ÕÕÕÕÕÕÕ SET THE PIT (8253) TIMER NUMBER 0 TO THE VALUE IN AX REGISTER ÕÕÕÕÕ
  154.     shl eax,8
  155.     mov al,00110100b
  156.     out 43h,al
  157.         shr eax,8
  158.     out 40h,al
  159.         mov al,ah
  160.     out 40h,al
  161.         ret
  162. Set_timer endp
  163.  
  164.  
  165.  
  166.  
  167.  
  168. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕPRINT TEXTÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  169. ; PRINTS A STRING ON SCREEN ( TEXT MODE 3 )
  170. ; Expects  edx             > offset of string in the data segment
  171. ;       Cursor_X,Cursor_Y     >  position (X,Y) on the screen
  172. ;       ah                  > attribute byte ( colors )
  173. ;NOTE:  string ends with a '$'
  174. ;      Cursor_X is returned with the X position at the end of the string
  175. TEXT proc near
  176.            push eax edx
  177. textlop:    mov al,[edx]
  178.                 inc edx
  179.             cmp al,'$'
  180.             jz exit_text
  181.             call print_char
  182.                jmp textlop
  183. exit_text:     pop edx eax
  184.         ret
  185. TEXT ENDP
  186.  
  187. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT BINARY NUMBER OF THE REGISTER EDXÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  188. ; Similar to the TEXT proc near above
  189. ; Expects :
  190. ; ah = color
  191. ; Cursor_X,Cursor_Y   position (X,Y) on the screen
  192. ;
  193. binary_Dword    proc near            ; prints EDX
  194.         push ecx
  195.     mov ecx,32
  196.     jmp binSizeSet
  197. binary_Word    proc near            ; prints DX
  198.         push ecx
  199.     mov ecx,16
  200.         rol edx,16
  201.     jmp binSizeSet
  202. binary_Byte    proc near            ; prints DL
  203.                 push ecx
  204.         mov ecx,8
  205.             rol edx,24
  206. BinSizeSet:    push eax
  207.     binary_digit:
  208.                 mov al,'0'
  209.                 rol edx,1
  210.                 jnc bin_p_0
  211.                mov al,'1'
  212.           bin_p_0: call print_char    ;prints a char al : color = ah
  213.             loop binary_digit
  214.                 pop eax ecx
  215.             ret
  216. Binary_Byte endp
  217. Binary_Word endp
  218. Binary_DWord endp
  219.  
  220. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕPRINT HEXIDECIMAL NUMBER OF THE REGISTER EDXÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  221. ; Expects :
  222. ; ah = color
  223. ; Cursor_X,Cursor_Y   position (X,Y) on the screen
  224. ;
  225. Hex_Dword    proc near            ; prints EDX
  226.         push ecx
  227.     mov ecx,8
  228.     jmp strt_hex
  229. Hex_Word    proc near            ; prints DX
  230.         push ecx
  231.     mov ecx,4
  232.         rol edx,16
  233.     jmp strt_hex
  234. Hex_Byte    proc near            ; prints DL
  235.         push ecx
  236.         rol edx,24
  237.     mov ecx,2
  238. strt_hex:
  239.         push esi
  240. HexPrnt:        rol edx,4
  241.                 mov esi,edx
  242.                 and esi,0fh
  243.                 mov al,HexChar+esi
  244.                 call print_char
  245.               Loop HexPrnt
  246.                 pop esi ecx
  247.             ret
  248. endp
  249. endp
  250. endp
  251.  
  252.  
  253. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT DECIMAL NUMBER OF THE REGISTER EDX ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  254. ; Expects :
  255. ; ah = color
  256. ; Cursor_X,Cursor_Y   position (X,Y) on the screen
  257. ;
  258.  
  259. DEC_Dword    proc near            ; prints EDX
  260.         push ecx esi edx
  261.     mov ESI,9*4
  262.     jmp strt_dec
  263. DEC_Word    proc near            ; prints DX
  264.         push ecx esi edx
  265.     mov ESI,4*4
  266.     and edx,0FFFFh
  267.     jmp strt_dec
  268. DEC_Byte    proc near            ; prints DL
  269.         push ecx esi edx
  270.            mov ESI,2*4
  271.     and edx,0FFh
  272.  
  273. DATA32 SEGMENT PUBLIC 'DATA' use32
  274. dec_diver dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
  275. DecVal23    dd 0
  276. tmpdec_color07    db 0
  277. ENDS
  278.  
  279. strt_dec:
  280.     push EAX
  281.         mov tmpdec_color07,ah    ; save color
  282.         mov decVal23,EDX
  283. dec83:  mov ECX, Dec_diver + ESI
  284.  
  285.         mov eax,decVal23
  286.         xor edx,edx
  287.         div ECX
  288.         mov DecVal23,EDX    ; use remainder
  289.                     ; use quot as digit number
  290.         add al,'0'    ; print digit
  291.             mov ah,tmpdec_color07
  292.             call print_char
  293.         sub ESI,4
  294.         jge dec83
  295.  
  296.     pop EAX EDX ESI ECX
  297.            ret
  298. endp
  299. endp
  300. endp
  301.  
  302.  
  303.  
  304.  
  305.  
  306. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ PRINT A CHARACTER ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  307. ; EXPECTS:
  308. ; al     character to print
  309. ; ah      attribute byte
  310. ; Cursor_X,Cursor_Y   position (X,Y) on the screen
  311. PRINT_CHAR    proc near
  312.                 ;-- line feed ----------------------------------
  313.                 cmp al,0Ah
  314.                 jnz no_feed
  315.                   inc Cursor_Y       ; move curser down a line
  316.             jmp char_printed
  317. no_feed:    ;-- carage return ------------------------------------
  318.                 cmp al,0Dh
  319.                 jnz no_carg
  320.                   mov Cursor_X,0        ; return curser to start
  321.             jmp char_printed
  322.    no_carg:    ;-- print the character on the screen -----------------
  323.                push eax ecx
  324.                 mov ecx,eax
  325.                 xor eax,eax
  326.                 mov eax,80
  327.                 mul Cursor_Y
  328.                 add ax,word ptr Cursor_X
  329.                 mov fs:[0b8000h+2*eax],CX
  330.                 inc Cursor_X
  331.         pop ecx eax
  332.  
  333.         ; ----- don't let the curser go off the screen -----------
  334. char_printed:      cmp Cursor_X,80
  335.              jb k23
  336.               mov Cursor_X,0
  337.                   inc Cursor_Y
  338.     k23:      cmp Cursor_Y,25
  339.              jb k24
  340.                   call Scroll_Screen
  341.               mov Cursor_Y,24
  342.     k24:      ret
  343. endp
  344.  
  345.  
  346.  
  347.  
  348.  
  349. SQRT    proc near
  350. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  351. ; returns EAX with the SQUARE ROOT of EAX.
  352. ;
  353. ; Uses newtons method:    Xn+1 = Xn -  f(Xn) / f'(Xn)
  354. ;    f'(x) is the derivitive of f(x)
  355. ;
  356. ; For square routes:  f(x) = x*x - ( Root value  i.e EAX)
  357. ;  and        f'(x) = 2x
  358. ;
  359. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  360. ;
  361.         mov edi,eax
  362. ;----- Get Estimated Root Value ( ebp = rough value of the sqrt of EAX ) ---
  363.             bsr ecx,edi    ; Get bit number of highest NZ bit
  364.             shr cl,1    ; Half this highest bit number
  365.         mov ebp,edi     ; Rotate Root Value by
  366.         shr ebp,cl    ;  the bit number to get a estimate root.
  367.  
  368.  
  369. ;----- Main Loop that makes EBP converge to the square root of EDI ------
  370.  calc_sqrt_Loop:
  371.         push EBP        ; save x  so can check if x has converged
  372.         mov  EBX,EBP
  373.         shl  EBX,1        ; ebx = f'(x) = 2x
  374.  
  375.         mov  EAX,EBP
  376.         mul  EBP
  377.         sub  EAX,EDI        ; eax = f(x) = X*X - Root_value
  378.         sbb  EDX,0        ; use 64bit subtract
  379.  
  380.         div  EBX        ; eax = f(Xn) / f'(Xn)
  381.  
  382.     sub  EBP,EAX        ; ebp =   Xn+1   =   Xn - f(Xn) / f'(Xn)
  383.         pop  EAX        ; look at old value
  384.         cmp  EBP,EAX        ; loop only if new value is different
  385.       jnz calc_sqrt_Loop
  386. ;-------------------------- End of Loop --------------------------------
  387.  
  388.         mov eax,ebp    ; EBP contians the square root of EDI
  389.     ret
  390. ;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  391. endp
  392.  
  393.  
  394.  
  395. Random proc near
  396. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  397. ;        EAX =  a random number CL bits in size
  398. ;
  399. ;ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ
  400.         xor eax,eax
  401.         mov bl,byte ptr random_init
  402.         and bl,1
  403.  
  404. Gen_bit:    ; make n bit numbers
  405.         shl eax,1
  406.  
  407.         mov edx,random_init
  408.  
  409.         shr edx,9
  410.         xor bl,dl
  411.  
  412.         shr edx,5
  413.         xor bl,dl
  414.  
  415.         bt ebx,1
  416.         rcr random_init,1
  417.         setc bl
  418.     or  al,bl
  419.  
  420.     dec cl
  421.         jnz Gen_bit
  422.     ret
  423. ;ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
  424. endp
  425.  
  426.